<template>
<view class="all">
   <!-- 余额 -->
   <view class="myMoney">
      <view class="moneyTitle">
         <text>账户余额(元)</text>
         <!-- <image src='../../img/question.png'></image> -->
      </view>
      <view class="sellMoney">
         {{moneyList}}
      </view>
      <view class="recharge">
         <view @tap="toRecharge">充值</view>
      </view>
   </view>
   <!-- 明细 -->
   <view class="detailed">
      <view class="detailedTitle">消费明细</view>
   </view>
   <!-- 明细列表 -->
   <view v-for="(item, index) in detailList" :key="index" class="detailedNav">
      <view class="detailedNavList">
         <view class="listTop">
            <view v-if="item.type == 1">提现</view>
            <view v-if="item.type == 3">支付订单</view>
            <view style="font-size:34rpx">+{{item.amount}}</view>
         </view>
         <view class="listBottom">
            {{item.add_time}}
         </view>
      </view>
   </view>
</view>
</template>

<script>
var app = getApp();
import api from "../../../api";

export default {
  data() {
    return {
      uid: '',
      moneyList: '0.00',
      detailList: []
    };
  },

  components: {},
  props: {},

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.getStorage({
      key: 'userId',
      success: res => {
        console.log(res);
        this.setData({
          uid: res.data
        });
        this.getList();
        this.detList();
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getList();
    this.detList();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
  methods: {
    // 路由
    toRecharge: function () {
      wx.navigateTo({
        url: '../recharge/recharge?moneyList=' + this.moneyList
      });
    },
    //余额
    getList: function () {
      app.globalData.request({
        url: api.default.user_wallet,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.uid
        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({
            moneyList: res.balance
          });
        }
      });
    },
    //消费明细
    detList: function () {
      app.globalData.request({
        url: api.default.user_wallet_bill,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        data: {
          uid: this.uid
        },
        method: 'POST',
        success: res => {
          console.log(res);
          this.setData({
            detailList: res
          });
        }
      });
    }
  }
};
</script>
<style>
@import "./myMoney.css";
</style>